package edu.jxut.reggie.server.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import edu.jxut.reggie.mapper.EmployeeMapper;
import edu.jxut.reggie.pojos.Employee;
import edu.jxut.reggie.server.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    public Page<Employee> selectListPage(int page,int pageSize,String name) {
        Page<Employee> employeePage = new Page<>();
        employeePage.setPages(page);
        employeePage.setSize(pageSize);
        if (name==null) {
            Page<Employee> employeePage1 = employeeMapper.selectPage(employeePage, null);
            //清除密码并返回
//            employeePage1.getRecords().stream().forEach(e->e.setPassword(""));
            return employeePage1;
        }else{
            Page<Employee> employeePage1 = employeeMapper.selectPage(employeePage, new LambdaQueryWrapper<Employee>().like(Employee::getName, name));
            //清除密码并返回
//            employeePage1.getRecords().stream().forEach(e->e.setPassword(""));
            return employeePage1;
        }
    }
}